Skip to content

GH-471: Fix ListView reader iteration bounds - #1310

Merged
jbonofre merged 1 commit into
apache:mainfrom
PNHD:fix/471-listview-reader-iteration
Oct 3, 2026
Merged

jbonofre merged 1 commit into
apache:mainfrom
PNHD:fix/471-listview-reader-iteration

Conversation

@PNHD

@PNHD PNHD commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What's Changed

Fix UnionListViewReader and UnionLargeListViewReader iteration so non-empty
ListView values terminate after exactly the declared number of elements.

Closes #471.

@github-actions

This comment has been minimized.

@lidavidm lidavidm added the bug-fix PRs that fix a big. label Sep 25, 2026
@github-actions github-actions Bot added this to the 20.0.0 milestone Sep 25, 2026
}

@Test
public void testCopyFromNonEmptyListView() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you extend the coverage a bit here? Two cases would pin down #471:

  • the exact repro from the issue (non-nullable child, source built with startNewValue/endValue, 10 elements)
  • a multi-row copy, rows copied in order, that includes a null row and an empty row

writer.setValueCount(1);

outVector.allocateNew();
outVector.copyFrom(0, 0, inVector);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This passes because the reader is first obtained inside copyFrom, after the writes. If inVector.getReader() is called before writeIntValues(...), the copy produces [null, null]: the cached UnionListViewReader keeps its original data vector, because ListViewVector.invalidateReader() only clears reader, whereas ListVector.invalidateReader() also clears fieldReader.

This predates your changes, but it is a one-line fix and the easiest way to still get wrong data out of a flat copyFrom.

Would you mind including it here with a test? Otherwise I'm fine with a follow-up issue.

// the full list, we need to check if the currentOffset is less than the currentOffset + size
if (currentOffset < currentOffset + size) {
// Yield exactly the element count stored with this list view, beginning at its stored offset.
if (remaining > 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the bound in place, read(int index, UnionHolder holder) above now stops at the end of the view, but it still ignores the result of next(). For index >= size the holder ends up on the last element of the view with isSet = 1, and for an empty view on whatever the child reader was last positioned on.

UnionListReader.read has the same loop, so this isn't new here and I won't block on it. If you want to tighten it in both readers, something like:

boolean found = true;
for (int i = -1; i < index && found; i++) {
  found = next();
}
holder.reader = data.getReader();
holder.isSet = found && data.getReader().isSet() ? 1 : 0;

Either way, a test for the out-of-range and empty-view cases would be good: testReaderIteratesListViewRangeAndResets only covers an in-range index.

private final ValueVector data;
private int currentOffset;
private int size;
private int remaining;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: #471 points out that the approach differs from UnionListReader. Mirroring its currentOffset/maxOffset pair would keep the readers aligned and drop the extra decrement:

// setPosition
maxOffset = currentOffset + size;

// next
if (currentOffset < maxOffset) {
  data.getReader().setPosition(currentOffset++);
  return true;
}
return false;

Same in UnionLargeListViewReader, where checkedCastToiInt(currentOffset++) and its import could also go, since currentOffset is already an int.

largeListViewVector.setSize(0, 3);
largeListViewVector.setValueCount(1);

UnionLargeListViewReader reader = new UnionLargeListViewReader(largeListViewVector);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reader has to be built by hand here because LargeListViewVector.getReader(), getReaderImpl() and copyFrom() still throw UnsupportedOperationException, so nothing in production reaches the Large half of this fix yet. That's fine for this PR, but could you say so in the description?

While you are in UnionLargeListViewReader: getMinorType() returns MinorType.LISTVIEW. It should be MinorType.LARGELISTVIEW imho.

@jbonofre
jbonofre force-pushed the fix/471-listview-reader-iteration branch from 5b1c63a to 3b34830 Compare October 3, 2026 05:07
@jbonofre
jbonofre merged commit 1d8dc54 into apache:main Oct 3, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ListViewVector#copyFrom Throws IndexOutOfBoundsException on Non-Empty Elements

3 participants